package edu.cs.usask.ca.silver.plugin.rcp.jobs;

import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;

public class LoggerReportScheduler {

	public static void scheduleErrorLogging(final Logger logger,
			final String message, final Exception e) {
		Job job = new Job("error") {
			@Override
			protected IStatus run(IProgressMonitor monitor) {
				setPriority(DECORATE);
				if (e == null) {
					logger.error(message);
				} else {
					logger.error(message, e);
				}
				return Status.OK_STATUS;
			}

		};
		job.schedule();

	}

	public static void scheduleErrorLogging(final Logger logger,
			final String message) {
		Job job = new Job("error") {
			@Override
			protected IStatus run(IProgressMonitor monitor) {
				setPriority(DECORATE);
				logger.error(message);
				return Status.OK_STATUS;
			}

		};
		job.schedule();
	}

	public static void scheduleDebugLogging(final Logger logger,
			final String message, final Exception e) {
		Job job = new Job("error") {
			@Override
			protected IStatus run(IProgressMonitor monitor) {
				setPriority(DECORATE);
				if (e == null) {
					logger.debug(message);
				} else {
					logger.debug(message, e);
				}
				return Status.OK_STATUS;
			}
		};
		job.schedule();
	}

	public static void scheduleWarnLogging(final Logger logger,
			final String message, final Exception e) {
		Job job = new Job("error") {
			@Override
			protected IStatus run(IProgressMonitor monitor) {
				setPriority(DECORATE);
				if (e == null) {
					logger.warn(message);
				} else {
					logger.warn(message, e);
				}

				return Status.OK_STATUS;
			}

		};
		job.schedule();

	}

	public static void scheduleInfoLogging(final Logger logger,
			final String message) {
		Job job = new Job("error") {
			@Override
			protected IStatus run(IProgressMonitor monitor) {
				setPriority(DECORATE);
				logger.info(message);
				return Status.OK_STATUS;
			}

		};
		job.schedule();
	}
}
